#!/usr/bin/python
# -*- coding：utf-8 -*-


import pandas as pd
import numpy as np
import datetime
import  csv
import requests
import  demjson
import os

# pre函数，预测函数，无返回值，只需要根据输入的路径来输出一个预测结果的csv文件
def pre(input_path = "../data/总能量test.csv", output_path = "../data/能量.csv"):
	# 读取路径中的文件
	data = pd.read_csv(input_path,engine='python', encoding="utf_8_sig")
	data = data.rename(columns={'时间': 'SDATE'})
	data['tempavg'] = (data['temphigh'] + data['templow']) / 2
	data['tempavg'] = data['tempavg'].astype('int')
	data['ajwldl2.YC456'] = data['ajwldl2.YC456'] * (-1)
	data['SDATE'] = pd.to_datetime(data['SDATE'])
	data = data.loc[(data['SDATE'].dt.hour.isin([0, 6, 12, 18])) & (data['SDATE'].dt.minute == 0)]
	data.index = range(data.shape[0])  # 重置索引
	data['energy'] = data['ajwldl2.YC456'].shift(-1) - data['ajwldl2.YC456']
	data = data.drop(['ajwldl2.YC456'], axis=1)
	data = data.loc[(data['energy'] < 1500) & (data['energy'] > 400)]
	data.index = range(data.shape[0])  # 重置索引
	data['hour'] = data['SDATE'].dt.hour
	data.dropna(inplace=True)
	if os.path.exists(output_path):
		data.to_csv(output_path, encoding="utf_8_sig")
	else:
		data.to_csv(output_path, encoding="utf_8_sig")

if __name__ == '__main__':
    pre(input_path = "../data/总能量test.csv", output_path = "../data/能量.csv")